<template>
	<view id="home">
		<!--Header-->
		<view class="status_bar">
			<view class="header">
				<view class="store">
					Hi  你好 : {{userinfo.name}}({{userinfo.agentname}})
				</view>
				<view class="msg"  @click='urlTo("letter")'>
					<image src="../../static/index/sixin.png" class="letter"   alt="" />
					<text class="readNum" v-if='wread > 0'>{{wread}}</text>
				</view>
			</view>
		</view>
		<!--轮播-->
		<view class="wrap">
			<view class="lunbo">
				<swiper :autoplay="true" :interval="4000" :duration="1000" @change="changeBanner">
					<swiper-item v-for="(item,index) in index_lunbo" :key="index">
						<image :src="item.img" mode="" @click="urlTo('/pages/index/activityDetail?id='+item.url)"></image>
					</swiper-item>
				</swiper>
				<view class="dots">
					<block v-for="(item,index) in index_lunbo" :key="index">
						<view class="dot" :class="index== bannerIndex ? ' swiperActive' : ''"></view>
					</block>
				</view>
			</view>
			<!--公告-->
			<view class="notice dis-center">
				<image src="../../static/index/homeMsg.png" class="noticepic" mode="widthFix"></image>
				<scroll-view class="an-notice-content">
					<swiper class="swiper" :autoplay="true" :interval="5000" :duration="5000" :circular="true">
						<swiper-item v-for="(text, index) in index_notice" :key="index" class="an-notice-content-item" @click="urlTo('noticeDetail?id='+text.id)">
							<view class="swiper-item">
								<text class="an-notice-content-item-text">{{text.title}}</text>
							</view>
						</swiper-item>
					</swiper>
				</scroll-view>
			</view>
			<!--功能-->
			<view class="dataBox">
				<view class="dataNav">
					<image src="../../static/index/homePic1.png" @click="urlTo('activity')"></image>
				</view>
				<view class="dataNav">
					<image src="../../static/index/homePic2.png" @click="urlTo('share')"></image>
				</view>
				<view class="dataNav">
					<image src="../../static/index/homePic3.png" @click="urlTo('myMachine')"></image>
				</view>
				<view class="dataNav">
					<image src="../../static/index/homePic5.png" @click="urlTo('imgShare')"></image>
				</view>
				<view class="dataNav">
					<image src="../../static/index/homePic7.png" @click="urlTo('bank')"></image>
				</view>
				<view class="dataNav">
					<image src="../../static/index/homePic6.png" @click="urlTo('shop')"></image>
				</view>
			</view>
			<!--首页业绩-->
			<view style="background-color: #FFF;padding:10rpx 0;">
				<view class="profitBox">
					<view class="title">  累计收益 </view>
					<view class="profit">  {{data.totalMoney}}</view>
					<view class="month">
						<view class="monthList monthList1">
							<view class="num">{{data.callBack}}</view>
							<view class="name">机具返现(元)</view>
						</view>
<!-- 						<view class="monthList monthList1">
							<view class="num">{{data.cashBackFlow||0}}</view>
							<view class="name">流量费返现(元)</view>
						</view> -->
						<view class="monthList">
							<view class="num">{{data.fenrun}}</view>
							<view class="name">分润(元)</view>
						</view>
					</view>
				</view>
				<!--图表-->
				<view style="padding:20rpx;font-size:26rpx;">收益走势图</view>
				<qiun-data-charts type="line" :opts="chartConfig" :chartData="chartData" style="min-height: 300rpx;;"/>
			</view>
			<!--活动弹窗-->
			<uni-popup ref="active">
				<view class="activeBox" style="width:600rpx;margin:50rpx auto 0;position:relative" >
					<image class="code" :src="native_img" style="width:100%;border-radius:20rpx;" mode="widthFix" @click="toNative()"/>
					<view class="close" @tap="activeClose()" style="text-align: center;">
						<image src="@/static/my/close.png" style="margin:10px auto;width:60rpx;height:60rpx;"/>
					</view>
				</view>
			</uni-popup>
		</view>
		
		<yomol-upgrade  :type="upgradeType" :url="upgradeUrl" title="发现新版本" :content="upgradeContent" ref="yomolUpgrade"></yomol-upgrade>
	</view>
</template>
<script>
	import yomolUpgrade from '../../components/yomol-upgrade/yomol-upgrade.vue'
	export default {
		components: {
			yomolUpgrade
		},
		data() {
			return {
				userinfo:'',
				flag: '',
				index_lunbo:[],
				index_notice:[],
				duration: 1000,
				bannerIndex:0,
				wread:'',
				homeData:{},
				data:'',
				chartConfig:{
					legend:{
						show:false//是否显示图例
					},
					xAxis:{
						fontSize:12,
						calibration:true
					}
				},
				chartData: {
					categories:[],
					series:[]
				},
				native_img:'',
				native_id:'',
				
				upgradeType: 'pkg', //pkg 整包 wgt 升级包
				upgradeContent: '', //更新内容
				upgradeUrl: '', //更新地址
			}
		},
		onShow() {
			//检测协议
			//this.checkIsConfirm()
			// console.info(this.userinfo)
			// 这里不能放接口，否则更新app在安装时候一直触发app下载
		},
		onLoad() {
			this.getEbar()
			this.getIndexData()
			this.getIndexProfit()
			this.getChartData()
			this.getUserInfo()
			// #ifdef APP-PLUS
			// this.checkVersion()
			// #endif
		},
		methods: {
			getEbar(){
				this.httpClient.post('profit/app/profitSum/getIsHaveDhd', {}).then(res => {
					if(res.data>0){
						let size=''
						if(res.data>99){
							size=99
						}else{
							size=res.data
						}
						console.info(size)
						uni.setTabBarBadge({
							index: 2, //tabbar下标
							text:size.toString()
						})
					}else{
						uni.removeTabBarBadge()
					}
				})
			},
			//合作商信息*
			getUserInfo(){
				this.httpClient.post('agents/app/agent/getUserInfoForApp', {}).then(res => {
					if(res.code){
						this.userinfo=res.data
						uni.setStorageSync('userInfo',res.data)
						if(res.data.isConfirm==1){
							uni.redirectTo({
								url:'/pages/my/info'
							})
						}
					}
				})
			},
			//身份确认*
			checkIsConfirm(){
				this.httpClient.post('agents/app/agent/index/checkIsConfirm', {}).then(res => {
					if(res.code==200 && res.data==1){
						uni.showToast({
							icon:'none',
							duration: 2500,
							title: '当前未身份未确认,现在前往确认信息..'
						})
						setTimeout(function() {
							uni.reLaunch({
								url:'/pages/my/info'
							})
						},1500)
					}else{
						this.getIndexActive()
					}
				})
			},
			
			
			//活动弹窗*
			getIndexActive(){
				this.httpClient.post('agents/app/activity/getDump', {}).then(res => {
					if(res.code==200){
						this.native_img=res.data.cover
						this.native_id=res.data.id
						if(res.data.cover1){
							this.$refs.active.open("center")
						}
						
					}
				})
			},
			//跳转活动
			toNative(){
				console.info(this.native_id)
				uni.navigateTo({
					url:'activityDetail?id='+this.native_id
				})
			},
			//关闭活动
			activeClose(){
				this.$refs.active.close()
			},
			//获取首页轮收据：轮播图、公告、活动*
			getIndexData(){
				this.httpClient.post('agents/app/agent/index/index', {}).then(res => {
					if(res.code==200){
						this.homeData = res.data
						this.index_lunbo=res.data.lunbo
						this.index_notice=res.data.noticeList
						this.wread = res.data.wread
					}
				})
			},
			//首页数据
			getChartData(){
				this.httpClient.post('profit/app/profitSum/tableDataAlls', {}).then(res => {
					if(res.code==200){
						this.chartData={
							categories:res.data.mon,
							series: [{
								name:'收益',
								data: res.data.data
							}]
						}
						console.info(this.chartData)
					}
				})
			},
			//收益数据
			getIndexProfit(){
				this.httpClient.post('profit/app/profitSum/index', {}).then(res => {
					if(res.code==200){
						this.data=res.data
					}
				})
			},
			//轮播图切换
			changeBanner(e) {
				this.bannerIndex = e.detail.current
			},
			//页面跳转
			urlTo(url){
				if(url){
					uni.navigateTo({
						url:url
					})
				}				
			},
			//版本检测*
			checkVersion(){
				let that=this
				plus.runtime.getProperty(plus.runtime.appid, (resInfo) => {
					//设备：iso,android
					let devType=0
					let platform = plus.os.name
					if(platform=='ios'){
						devType=1
					}
					this.httpClient.post('agents/app/agent/index/checkVer', {
						ver: resInfo.version,
						type:devType,
					}).then(res => {
						if(res.code==200){
							if(res.data){
								that.upgradeContent = res.data.content	//更新内容
								that.upgradeUrl = res.data.src	//更新地址
								that.$refs.yomolUpgrade.show()
							}
						}
					})
				})
			}
		}
	}
</script>
<style lang="scss" scoped>
	#home{
		position:relative;
		height:100%;
		.status_bar{
			height: 250rpx;
			width: 100%;
			.header {
				position: fixed;
			    top: 0;  
			    background-image: url('../../static/index/homeBg.png');
			    height: 250rpx;
			    background-size: 100% 100%;
			    color:#fff;
			    padding:0 1rem;
			    position: relative;
			    display: flex;
			    align-items: center;
				z-index:0;
				.store {
					flex:2;
				}
				.msg{
					flex:1;text-align:right;padding-right:1rem;position:relative;height:1.5rem;
					.letter {
						width: 1.5rem;
						height: 1.5rem;
					}
					.readNum {
						display: inline-block;
						position: absolute;
						right: 0.5rem;
						height: 1.2rem;
						width: 1.2rem;
						border-radius: 50%;
						text-align: center;
						line-height: 1.2rem;
						color: #fff;
						font-size: 0.7rem;
						background: #f00;
						margin-top: -0.5rem;
					}
				}
			
				
				
				
			}
		}
		
		
		.wrap{
			position: absolute;
			z-index:999;
			top: 170rpx;
			width: 100%;
			    left: 0;
				bottom:0;
			    overflow: scroll;
			    -webkit-overflow-scrolling:touch;
		}
		
		.lunbo {
			position:relative;margin:0rpx 20rpx 10rpx;border-radius: 20rpx;
			.activeList {
				padding: 0 30rpx;
				margin: 10rpx 0;
			}
			uni-swiper{
				height:350rpx;
			}
		
			image {
				width: 100%;
				height: 350rpx;
				box-shadow: 0 2px 12px 0 rgba(0, 0, 0, .1);
				border-radius: 20rpx;
			}
			.dots {
				position: absolute;
				bottom: 15rpx;
				left: 50%;
				// 这里一定要注意兼容不然很可能踩坑          
				transform: translate(-50%, 0);
				-webkit-transform: translate(-50%, 0);
				z-index: 99;
				display: flex;
				flex-direction: row;
				justify-content: center;
			
				.dot {
					width: 40rpx;
					height: 10rpx;
					border-radius: 5rpx;
					transition: all .6s;
					background: #E0E0E0;
					margin-right: 10rpx;
				}
			
				.swiperActive {
					width: 40rpx;
					height: 10rpx;
					background: #7EC8FF;
				}
			}
		}
		//公告
		.notice {
			height: 90rpx;overflow: hidden;background: #FFF;padding: 0 30rpx;
			.noticeLeft {
				display: flex;align-items: center;
				.noticeImg {
					width: 212rpx;height: 44rpx;
				}
				text{
						margin: 0 10rpx;
					}
			}
			uni-swiper {
				height: 100%;
			}
			.noticepic {
				width: 45rpx;
				margin-right: 30rpx;
				vertical-align: middle;
			}
			.an-notice-content {
				height: 86upx;width: calc(100% - 240upx);margin-left: 10rpx;position: relative;font-size: 30rpx;color: #757575;
			}
			.an-notice-content-item {
				width: 100%;height: 60upx;text-align: left;line-height: 86upx;
			}
			
			.an-notice-content-item-text {
				display: block;white-space: nowrap;text-overflow: ellipsis;overflow: hidden;
			}
		}
		//功能
		.dataBox{
			background-color: #FFF;margin:10rpx 0;padding:5rpx;
			.dataNav{
				width:350rpx;height:172rpx;display:inline-block;position:relative;margin:10rpx;
				image{
					width:100%;height:100%;
				}
			}
		}
		//首页业绩
		.profitBox {
			margin: 20rpx;
		       background-image: url('@/static/index/homeProfit1.png');
		       background-size: 100% 100%;
		       color: #fff;
		       border-radius: 20rpx;
		       padding: 10rpx 0 30rpx 0;
			   .title{
				   padding: 10rpx;
				   text-align: center;
			   }
			   .profit{
				   text-align: center;
				   font-size: 32rpx;;
				   font-weight: 600;
				   padding: 10rpx 0;
			   }
			   
			   .month {
			          width: 100%;
			          margin-top: 15rpx;
					  padding:10rpx 0;
			          display: flex;
			          align-items: center;
					  .monthList{
						  flex: 1;
						  font-size: 0.75rem;
						  text-align: center;
						  position: relative;
					  }
					  .monthList1:before{
						  content:'';
						  width: 1px;
						  height: 30rpx;;
						  position: absolute;
						  top: 50%;
						  right: 0;
						  margin-top: -0.6rem;
						  background: #fff;
					  }
			      }
			     
		   }
	}
	
</style>